// TODO I don know how to write the validator prettier
export function validateRegister(data) {
  const {
    phone, role, password, userId
  } = data;
  return {
    phoneVR: validatePhone(phone),
    roleVR: validateRole(role),
    passwordVR: validatePassword(password),
    userIdVR: validateUserId(userId)
  };
}

export function validatePhone(value) {
  if (!(/^1[3456789]\d{9}$/.test(value))) {
    return ['手机号错误', 'phone'];
  }
  return true;
}

function validateRole(value) {
  // TODO I don know how to write it prettier
  if (Number.isInteger(value) && value > 0 && value < 4) {
    return true;
  }
  return ['角色未选择', 'role'];
}

function validatePassword(value) {
  if (typeof value !== 'string' || value.trim().length === 0) {
    return ['密码错误', 'password'];
  }
  return true;
}

function validateUserId(value) {
  if (typeof value !== 'string' || value.trim().length === 0) {
    return ['工号错误', 'userId'];
  }
  return true;
}
